<template>
	<view>

		<view class="top-wrap">

			<text class="money-all">{{totalIncome|| '0.00'}}</text>
			<text style="font-size: 28upx;color: #A7A7A7;margin-top: 10upx;">累计收益(元)</text>

			<view class="withdraw-wrap">
				<text style="font-size: 28upx;color: #333333;margin-left: 30upx;">可提现金额：￥{{balance || '0.00'}}</text>

				<text class="btn-detail" style="margin-right: 30upx;" @click="gowithdraw">提现</text>
			</view>
		</view>

		<view class="wrap">
			<view style="background-color: #FFFFFF; position: sticky; top: 0;z-index: 2;">

				<u-tabs :list="tabs" ref="tabs" :current="current" keyName="name" 
					@click="change" activeColor="{color:#009CF9}" inactiveColor="{color:#606266}" :scrollable="false">
				</u-tabs>
			</view>
            
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view v-if="current === 0" style="margin-top: 2upx;">
					<view v-for="(item, index) in inList" :key="index" @click="itemClick(item)">
						<view class="income_list">
							<view class="income-item">
								<view class="income-title">
									<text class="income-title-name">{{item.buyersVxName|filterNull}}</text>
									<text class="income-title-level">{{item.fsInfo}}</text>
								</view>
								<text class="income-time">{{item.tradingHours|filterNull}}</text>
							</view>
							<text class="income-money">￥{{item.earningsAmount|filterNull}}</text>
				            
						</view>
						<u-line color="#efefef"></u-line>
					</view>
				</view>
				
				<view v-if="current === 1" style="margin-top: 2upx;">
					<view v-for="(item, index) in outList" :key="index" @click="itemClick(item)">
						<view class="income_list">
							<view class="income-item">
								<view class="income-title">
									<text class="income-title-name">{{item.tradingChannel|tradingChannel}}</text>
								</view>
				            
								<text class="income-time">{{item.applyTime|filterNull}}</text>
							</view>
				            
							<text class="income-money">￥{{item.applyAmount|filterNull}}</text>
				            
						</view>
				            
						<u-line color="#efefef"></u-line>
					</view>
				</view>	
			</mescroll-body>
			
		</view>
		
	</view>
</template>

<script>
	import {
		memberAccount,
		apiReturnsDetailedList,
		withdrawalRecord
	} from '@/api/marketing-api.js';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				tabs: [{
						name: '收益明细'
					},
					{
						name: '使用明细'
					}
				],
				balance: '',
				totalIncome: '',
				current: 0,
				inList: [],
				outList: [],
			
			}
		},
		onLoad() {
			this.getData();
		},
		methods: {

			getData() {
				//获取累积收益及提现金额
				memberAccount(
					this.$store.state.user.userInfo.memberNo
				).then(res => {
					this.balance = res.data.balance;
					this.totalIncome = res.data.totalIncome;
				})
			},

			//客户收益明细
			upCallback(page) {
				if(this.current == 0) {
					//收益明细
					apiReturnsDetailedList({
						memberNo: this.$store.state.user.userInfo.memberNo,
						pageNo: page.num,
						pageSize: page.size
					}).then(res => {
						this.mescroll.endSuccess(res.data.length);
						//设置列表数据
						if (page.num == 1) this.inList = []; //如果是第一页需手动制空列表
						this.inList = this.inList.concat(res.data); //追加新数据
					}).catch(() => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})
				}else {
					//使用明细
					withdrawalRecord({
						memberNo: this.$store.state.user.userInfo.memberNo,
						pageNo: page.num,
						pageSize: page.size
					}).then(res => {
						this.mescroll.endSuccess(res.data.length);
						//设置列表数据
						if (page.num == 1) this.outList = []; //如果是第一页需手动制空列表
						this.outList = this.outList.concat(res.data); //追加新数据
					}).catch(() => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})
				}	
			},
			// tab栏切换
			change(item) {
				this.current = item.index;
				this.mescroll.triggerDownScroll();
			},
			gowithdraw() {
				uni.navigateTo({
					url: '../withdraw/withdraw'
				})
			},


		}
	}
</script>

<style lang="scss" scoped>
	.top-wrap {
		@include flex(column);
		align-items: center;
		height: 256upx;
		background-color: $bg-white-color;

		.money-all {
			font-size: 45upx;
			font-weight: bold;
			color: $main-color;
			margin-top: 30upx;
		}

		.withdraw-wrap {
			width: 100%;
			@include flex;
			justify-content: space-between;
			margin: 20upx 0 0;
			align-items: center;

		}
	}

	.wrap {
		margin-top: 20upx;
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top) - 276upx);
		width: 100%;
	}

	.swiper-box {
		flex-grow: 1;
	}

	.swiper-item {
		height: 100%;
	}

	.income_list {
		@include flex;
		width: 100%;
		height: 130upx;
		align-items: center;
		background-color: $bg-white-color;

		image {
			width: 60upx;
			height: 60upx;
			margin-left: 40upx;
		}

		.income-item {
			flex-grow: 1;
			margin-left: 20upx;
			@include flex(column);

			.income-title {
				@include flex;
				align-items: center;

				.income-title-name {
					font-size: 28upx;
					color: $text-color-33;
					margin-right: 10upx;
				}

				.income-title-level {
					font-size: 24upx;
					color: $bg-white-color;
					line-height: 45upx;
					text-align: center;
					padding: 0 18upx;
					border-radius: 90upx;
					background-color: $main-color;
				}

			}

			.income-time {
				font-size: 26upx;
				color: $text-color-66;
				margin-top: 10upx;
			}
		}

		.income-money {
			color: $main-color;
			font-weight: bold;
			font-size: 28upx;
			margin-right: 40upx;
		}

	}

	.btn-detail {
		width: 180upx;
		height: 60upx;
		border-radius: 50upx;
		color: white;
		text-align: center;
		background-color: $main-color;
		font-size: 26upx;
		line-height: 60upx;
		margin: 10upx;
		align-self: flex-end;
	}
</style>
